from datetime import datetime
from enum import Enum
from typing import List, Optional, Union

class OrderStatus(Enum):
    """订单状态枚举"""
    CREATE = "CREATE"
    PAID = "PAID"
    SHIPPING = "SHIPPING"
    DELIVERED = "DELIVERED"
    CANCEL = "CANCEL"

class Payment:
    """支付方式抽象基类"""
    def __init__(self, amount: float):
        self.amount = amount
    
    def process_payment(self) -> bool:
        """处理支付"""
        return True

class Credit(Payment):
    """信用卡支付"""
    def __init__(self, amount: float, number: str, type_: str, expireDate: datetime):
        super().__init__(amount)
        self.number = number
        self.type = type_
        self.expireDate = expireDate

class Cash(Payment):
    """现金支付"""
    def __init__(self, amount: float, cashTendered: float):
        super().__init__(amount)
        self.cashTendered = cashTendered

class WireTransfer(Payment):
    """在线转账"""
    def __init__(self, amount: float, bankID: str, bankName: str):
        super().__init__(amount)
        self.bankID = bankID
        self.bankName = bankName

class AliPay(Payment):
    """支付宝支付"""
    def __init__(self, amount: float, number: str):
        super().__init__(amount)
        self.number = number

class WeixinPay(Payment):
    """微信支付"""
    def __init__(self, amount: float, number: str):
        super().__init__(amount)
        self.number = number

class Product:
    """商品类"""
    def __init__(self, title: str, weight: float, description: str):
        self.title = title
        self.weight = weight
        self.description = description
    
    def getPriceForQuantity(self, quantity: int) -> float:
        """根据数量获取价格"""
        # 简化实现，实际中应该有自己的价格逻辑
        base_price = 100.0  # 基础价格
        return base_price * quantity
    
    def getWeight(self) -> float:
        """获取商品重量"""
        return self.weight

class OrderDetail:
    """订单详情类"""
    def __init__(self, quantity: int):
        self.quantity = quantity
        self.product: Optional[Product] = None
    
    def calculateSubTotal(self) -> float:
        """计算小计"""
        if self.product:
            return self.product.getPriceForQuantity(self.quantity)
        return 0.0
    
    def calculateWeight(self) -> float:
        """计算重量"""
        if self.product:
            return self.product.getWeight() * self.quantity
        return 0.0

class Order:
    """订单类"""
    def __init__(self, createDate: datetime):
        self.createDate = createDate
        self.status = OrderStatus.CREATE
        self.orderDetails: List[OrderDetail] = []
        self.payment: Optional[Payment] = None
    
    def addOrderDetail(self, orderDetail: OrderDetail) -> None:
        """添加订单详情"""
        self.orderDetails.append(orderDetail)
    
    def setPayment(self, payment: Payment) -> None:
        """设置支付方式"""
        self.payment = payment
        if payment:
            self.status = OrderStatus.PAID
    
    def getTotalAmount(self) -> float:
        """计算订单总金额"""
        return sum(detail.calculateSubTotal() for detail in self.orderDetails)
    
    def getTotalWeight(self) -> float:
        """计算订单总重量"""
        return sum(detail.calculateWeight() for detail in self.orderDetails)

class Customer:
    """客户类"""
    def __init__(self, name: str, contact: str, deliveryAddress: str, active: bool = True):
        self.name = name
        self.contact = contact
        self.deliveryAddress = deliveryAddress
        self.active = active
        self.orders: List[Order] = []
    
    def placeOrder(self, order: Order) -> None:
        """下订单"""
        if self.active:
            self.orders.append(order)
    
    def getOrderHistory(self) -> List[Order]:
        """获取订单历史"""
        return self.orders